package com.gaofeng.day07;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class demo3 {
    public static void main(String[] args) {
        // 创建一个Hashmap
        Map<String, String> map = new HashMap<>();
        //添加元素
        map.put("标枪选手", "马超");
        map.put("剑圣选手", "赵云");
        map.put("神射手选手", "黄忠");
        map.put("辅助选手", "姜维");

        Set<Map.Entry<String, String>> entries = map.entrySet();

        // 遍历HashMap
        for (Map.Entry<String, String> entry : entries) {

            // 获取键

            String key = entry.getKey();

            // 获取值

            String value = entry.getValue();

            System.out.println(key + "---" + value);
        }

        // lambda表达式遍历HashMap

        map.forEach((key, value) -> System.out.println(key + "---" + value));


    }
}
